<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="6">
            <a-form-item label="仓库名称">
              <a-input v-model="queryParam.warehouseName" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button icon="search" type="primary" @click="searchQuery">查询</a-button>
      <a-button icon="reload" type="primary" @click="searchReset">重置</a-button>
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('仓库')">导出</a-button>
      <a-upload
        v-has="'warehouse:import'"
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :customRow="clickThenSelect"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleDelete(record.id)">删除</a>
        </span>
      </a-table>
    </div>

    <hfWarehouse-modal ref="modalForm" @ok="modalFormOk"></hfWarehouse-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import HfWarehouseModal from './modules/HfWarehouseModal'
import { getAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'

export default {
  name: 'HfWarehouseList',
  mixins: [JeecgListMixin],
  components: {
    HfWarehouseModal
  },
  data() {
    return {
      description: '仓库管理页面',
      // 表头
      columns: [
        {
          title: '仓库代码',
          align: 'center',
          dataIndex: 'warehouseCode'
        },
        {
          title: '仓库名称',
          align: 'center',
          dataIndex: 'warehouseName'
        },
        {
          title: '仓库助记码',
          align: 'center',
          dataIndex: 'warehouseMnemonic'
        },
        {
          title: '仓库管理员',
          align: 'center',
          dataIndex: 'warehouseManagerId_dictText'
        },
        {
          title: '仓库地址',
          align: 'center',
          dataIndex: 'warehouseAddress'
        },
        {
          title: '仓库座机号码',
          align: 'center',
          dataIndex: 'warehouseLandlineNumber'
        },
        {
          title: '仓库类型',
          align: 'center',
          dataIndex: 'warehouseTypeId_dictText'
        },
        {
          title: '描述',
          align: 'center',
          dataIndex: 'description'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/warehouse/hfWarehouse/list',
        delete: '/warehouse/hfWarehouse/delete',
        deleteBatch: '/warehouse/hfWarehouse/deleteBatch',
        exportXlsUrl: '/warehouse/hfWarehouse/exportXls',
        importExcelUrl: 'warehouse/hfWarehouse/importExcel'
      },
      dictOptions: {
        warehouseTypeId: []
      },
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '30', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      selectedMainId: '',
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {},
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(','), [record])
          }
        }
      }
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
      this.selectedMainId = ''
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId = selectedRowKeys[0]
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params)
        .then(res => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            this.ipagination.total = res.result.total
            this.ipagination.pageSize = res.result.total
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'warehouseCode', text: '仓库代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseName', text: '仓库名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseMnemonic', text: '仓库助记码', dictCode: '' })
      fieldList.push({ type: 'sel_user', value: 'warehouseManagerId', text: '仓库管理员' })
      fieldList.push({ type: 'string', value: 'warehouseAddress', text: '仓库地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseLandlineNumber', text: '仓库座机号码', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'warehouseTypeId',
        text: '仓库类型',
        dictCode: 'hf_warehouse_type,warehouse_type_name,id'
      })
      fieldList.push({ type: 'Text', value: 'description', text: '描述', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
